// 审核计划表
<template>
  <div class="app-container">
    <el-form :model="queryParams" ref="queryForm" size="small" :inline="true" v-show="showSearch">
      <el-form-item label="类型" prop="type">
        <el-select v-model="queryParams.type" clearable placeholder="请选择类型" size="small">
          <el-option label="内部" value="1"></el-option>
          <el-option label="外部" value="2"></el-option>
        </el-select>
      </el-form-item>
      <el-form-item label="年份" prop="year">
        <el-date-picker
          type="year"
          v-model="queryParams.year"
          format="yyyy"
          value-format="yyyy"
          :style="{ width: '100%' }"
          placeholder="请选择年份"
          clearable
        ></el-date-picker>
      </el-form-item>
      <el-form-item>
        <el-button type="primary" icon="el-icon-search" size="mini" @click="handleQuery">搜索</el-button>
        <el-button icon="el-icon-refresh" size="mini" @click="resetQuery">重置</el-button>
      </el-form-item>
    </el-form>
    <el-row :gutter="10" class="mb8">
      <el-col :span="1.5">
        <el-button
          type="primary"
          plain
          icon="el-icon-plus"
          size="mini"
          @click="handleAdd"
          v-hasPermi="['monitor:ledger:add']"
        >新增</el-button>
      </el-col>
      <el-col :span="1.5">
        <el-button
          type="success"
          plain
          icon="el-icon-edit"
          size="mini"
          :disabled="single"
          @click="handleUpdate"
          v-hasPermi="['monitor:ledger:edit']"
        >修改</el-button>
      </el-col>
      <el-col :span="1.5">
        <el-button
          type="danger"
          plain
          icon="el-icon-delete"
          size="mini"
          :disabled="multiple"
          @click="handleDelete"
          v-hasPermi="['monitor:ledger:remove']"
        >删除</el-button>
      </el-col>
      <el-col :span="1.5">
        <el-button
          type="warning"
          plain
          icon="el-icon-download"
          size="mini"
          @click="handleExport"
          v-hasPermi="['monitor:ledger:export']"
        >导出</el-button>
      </el-col>
      <el-col :span="1.5">
        <el-button
          type="warning"
          plain
          icon="el-icon-download"
          size="mini"
          @click="printBox"
          v-hasPermi="['monitor:ledger:print']"
        >打印</el-button>
      </el-col>
      <right-toolbar :showSearch.sync="showSearch" @queryTable="getList"></right-toolbar>
    </el-row>
    <el-table
      @selection-change="handleSelectionChange"
      fit
      v-loading="loading"
      border
      :data="dataList"
    >
      <el-table-column type="selection" width="55" align="center" />
      <el-table-column show-overflow-tooltip label="年度" min-width="200">
        <template slot-scope="scope">
          <span>{{ scope.row.year || "--" }}年度质量监控试验台账表</span>
        </template>
      </el-table-column>
      <el-table-column show-overflow-tooltip label="月份" min-width="200" prop="month">
        <template slot-scope="scope">
          <span>
            {{
            Number(scope.row.month) + '月'
            }}
          </span>
        </template>
      </el-table-column>
      <el-table-column show-overflow-tooltip label="创建人" prop="createByName" min-width="150" />
      <!-- <el-table-column label="是否启用" align="center">
        <template slot-scope="scope">
          <el-switch
            v-model="scope.row.effectStatus"
            :active-value="1"
            :inactive-value="0"
            @change="handleStatusChange(scope.row)"
          ></el-switch>
        </template>
      </el-table-column>-->
      <el-table-column
        label="操作"
        align="center"
        class-name="small-padding fixed-width"
        width="240"
        fixed="right"
      >
        <template slot-scope="scope">
          <el-button
            size="mini"
            type="text"
            icon="el-icon-view"
            v-hasPermi="['monitor:ledger:info']"
            @click="handleDetail(scope.row)"
          >详情</el-button>
          <el-button
            size="mini"
            type="text"
            icon="el-icon-edit"
            @click="handleUpdate(scope.row)"
            v-hasPermi="['monitor:ledger:edit']"
          >补充信息</el-button>
          <el-button
            size="mini"
            type="text"
            icon="el-icon-delete"
            @click="handleDelete(scope.row)"
            v-hasPermi="['monitor:ledger:remove']"
          >删除</el-button>
        </template>
      </el-table-column>
    </el-table>

    <pagination
      v-show="total > 0"
      :total="total"
      :page.sync="queryParams.pageNum"
      :limit.sync="queryParams.pageSize"
      @pagination="getList"
    />
    <!-- 打印模板位置 -->
    <PrintBox
      :checkNum="8"
      :printRow="printList"
      :checkLabel="'ledgerList'"
      :isVertical="false"
      id="printBox"
    >
      <template slot="title" slot-scope="scope">
        <div>{{ scope.item[0].year }}年度质量监控试验台账 STET/B/26-5</div>
      </template>
      <template slot-scope="scope">
        <!-- 表格  class  table-page  必须-->
        <table
          style="border-collapse: collapse; table-layout: fixed"
          border="1"
          cellspacing="0"
          class="table-page"
        >
          <tr style="height: 5mm">
            <td style="width: 30mm">序号</td>
            <td style="width: 40mm">登记时间</td>
            <td style="width: 30mm">类别（产品/项目/参数）</td>
            <td style="width: 45mm">产品/项目/参数</td>
            <td style="width: 50mm">能力验证文件编号</td>
            <td style="width: 50mm">能力验证方式</td>
            <td style="width: 100mm">参加人员</td>
            <td style="width: 50mm">比对试验方案编号</td>

            <td style="width: 40mm">评价结果</td>
          </tr>
          <tr v-for="(e, i) in 8">
            <td>{{ scope.item[i] && i + 1 }}</td>

            <td>
              {{
              scope.item[i] &&
              parseTime(scope.item[i].registerTime, "{y}-{m}-{d}")
              }}
            </td>
            <td>
              {{
              scope.item[i] && scope.item[i].lbcpxmcs
              }}
            </td>
            <td>{{ scope.item[i] && scope.item[i].cpxmcs }}</td>
            <td>
              {{
              scope.item[i] && scope.item[i].nlyzwjbh
              }}
            </td>

            <td>{{ scope.item[i] && scope.item[i].nlyzfs }}</td>
            <td>{{ scope.item[i] && scope.item[i].joinUser }}</td>
            <td>
              {{
              scope.item[i] && scope.item[i].bdsyfabh
              }}
            </td>

            <td>{{ scope.item[i] && scope.item[i].result }}</td>
          </tr>
        </table>
        <!-- 底部信息位置 -->
        <div
          class="desc"
          style="display: flex;
          text-align:left;
            align-items: center;
            }"
        >
          <!-- {{ baseUrl+scope.item[0].esign }} -->
          <div style="width: 30% display: flex;align-items: center;">
            登记人：
            <img :src="baseUrl + scope.item[0].esign" alt style="width: 80px; height: 30px;" />
          </div>
        </div>
        <div class="page-bottom" style="page-break-after: always">
          <div class="desc">注：本表格自2022年5月1日起生效</div>
        </div>
      </template>
    </PrintBox>
  </div>
</template>

<script>
import {
  listmonitorLedgerMain,
  delmonitorLedgerMain,
  getQualityMonitorLeaders
} from "@/api/quality/legder.js";
import printStyle from "@/utils/print.js";

export default {
  name: "legder",
  data() {
    return {
      baseUrl: this.$VUE_APP_IMG_API,
      // 选中数组
      ids: [],
      // 非单个禁用
      single: true,
      // 非多个禁用
      multiple: true,
      // 显示搜索条件
      dataList: [],
      // 遮罩层
      loading: true,
      // 显示搜索条件
      showSearch: true,
      // 总条数
      total: 0,
      // 查询参数
      queryParams: {
        pageNum: 1,
        pageSize: 10,
        year: undefined,
        type: ""
      },
      // 日期范围
      dateRange: [],
      infos: [], //勾选的数据
      printList: [],
      printParams: {
        ids: []
      }
    };
  },
  created() {
    const str = sessionStorage.getItem("queryParams");
    if (str) {
      this.queryParams = JSON.parse(str);
      setTimeout(() => {
        sessionStorage.removeItem("queryParams");
      }, 500);
    }
    this.getList();
  },
  methods: {
    printBox() {
      if (this.ids.length > 1) {
        this.$message({
          message: "请选单个数据进行打印",
          type: "warning"
        });
        return;
      }
      //infos  勾选的数据 如果有勾选就打印勾选。
      if (this.infos.length) {
        // this.printList = this.infos;
        this.printParams.ids = this.ids;
      }
      this.getQualityMonitorLeaders();
      setTimeout(() => {
        this.$print({
          printable: "printBox", //打印区域id
          type: "html", //打印类型是html
          scanStyles: false,
          targetStyles: ["*"],
          style: this.workStyle()
        });
      }, 500);
    },
    getQualityMonitorLeaders() {
      getQualityMonitorLeaders(this.printParams).then(res => {
        this.printList = res;
        console.log(this.printList);
      });
    },
    // 可以自定义样式  printStyle 是公共样式 切勿私自修改
    workStyle() {
      return `${printStyle}
        table,
        table tr th,
        table tr td {
          height:17mm;
          padding: 0px;
          font-size: 12px;
        }
        .desc{
        text-align: left; font-size: 12px; margin-top: 10px
      }
            .df {
                display: flex;
              }
      `;
    },
    // 多选框选中数据
    handleSelectionChange(selection) {
      this.ids = selection.map(item => item.qualityMonitorLedgerMainId);
      this.single = selection.length != 1;
      this.multiple = !selection.length;
      this.infos = selection;
    },

    /** 修改按钮操作 */
    handleUpdate(row) {
      sessionStorage.setItem("queryParams", JSON.stringify(this.queryParams));

      const configId = row.qualityMonitorLedgerMainId || this.ids;
      this.$router.push("./addLedger?isEdit=true&id=" + configId);
    },
    handleDetail(row) {
      sessionStorage.setItem("queryParams", JSON.stringify(this.queryParams));

      this.$router.push(
        "./addLedger?isInfo=true&id=" + row.qualityMonitorLedgerMainId
      );
    },

    /** 删除按钮操作 */
    handleDelete(row) {
      const configId = row.qualityMonitorLedgerMainId || this.ids;
      let name = this.checkRow(
        configId,
        this.dataList,
        "qualityMonitorLedgerMainId",
        "DELETE",
        "year"
      );
      this.$modal
        .confirm("是否确认删除" + name + "年度质量监控试验台账表的数据项？")
        .then(function() {
          return delmonitorLedgerMain(configId);
        })
        .then(() => {
          this.getList();
          this.$modal.msgSuccess("删除成功");
        })
        .catch(() => {});
    },
    handleAdd() {
      this.$router.push("./addLedger");
    },
    /** 查询列表 */
    getList() {
      this.loading = true;
      listmonitorLedgerMain(
        this.addDateRangeTime(
          this.queryParams,
          this.dateRange,
          "startAuditDate",
          "endAuditDate"
        )
      ).then(response => {
        this.dataList = response.rows;
        console.log(this.dataList);
        this.total = response.total;
        this.loading = false;
      });
    },
    handleExport() {
      this.download(
        "framework/monitorLedgerMain/export",
        {
          ...this.queryParams
        },
        `质量监控试验台账表_${this.parseTime(
          new Date().getTime(),
          "{y}-{m}-{d}"
        )}.xlsx`
      );
    },
    /** 搜索按钮操作 */
    handleQuery() {
      this.queryParams.pageNum = 1;
      this.getList();
    },
    /** 重置按钮操作 */
    resetQuery() {
      this.dateRange = [];
      this.resetForm("queryForm");
      this.handleQuery();
    }
  }
};
</script>
<style lang="scss" scoped>
::v-deep .el-dialog__body {
  img {
    width: 100%;
  }
}
</style>
